package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.model.Board;
import com.example.forum.services.IBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName BoardController
 * @Description TODO
 * @Author H.
 * @Date 2023/5/28 15:26
 * @Version 1.0
 */
@RequestMapping("/board")
@Slf4j
@Api(tags = "板块接口")
@RestController
public class BoardController {

    @Value("${forum.index.board-num:9}")
    private Integer indexBoardNum;

    //注入service层
    @Resource
    private IBoardService  boardService;
    /**
     * 查询首页板块信息
     * @return
     */
    @ApiOperation("主页显示中的板块")
    @GetMapping("/topList")
    public AppResult<List<Board>> topList(){
        log.info("从配置文件中读取到的板块数量为：" + indexBoardNum);
        List<Board> boards = boardService.selectTopByNum(indexBoardNum);
        return AppResult.success(boards);
    }

    @ApiOperation("获取板块详情")
    @GetMapping("/getById")
    public AppResult<Board> getBoardInfo(@ApiParam(value = "版块Id") @RequestParam(value = "id") @NonNull Long id){
        //调用service层方法
        Board board = boardService.selectById(id);
        return AppResult.success(board);
    }

}
